<template>
  <div>
    <el-table :data="list" border style="width: 100%">
      <el-table-column prop="id" label="角色编号"> </el-table-column>
      <el-table-column prop="rolename" label="角色名称"> </el-table-column>
      <el-table-column label="状态">
        <template slot-scope="scope">
          <div>
            <el-button type="info" v-if="scope.row.status == 1">启用</el-button>
            <el-button type="warning" v-else>禁用</el-button>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <div>
            <el-button type="success" @click="bianji(scope.row.id)">编辑</el-button>
            <v-del @del="del(scope.row.id)"></v-del>
          </div>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { mapActions, mapGetters } from "vuex";
import { roledelete } from "../../../request/api";
import {successAlert,warningAlert} from '../../../util/alert'
export default {
  data() {
    return {};
  },
  methods: {
    ...mapActions({
      reqchangelist: "role/reqchangelist",
    }),
    // 点击删除
    del(id) {
        roledelete({id:id}).then(res=>{
            if(res.data.code==200){
                successAlert(res.data.msg)
                // 重新请求数据
                this.reqchangelist()
            }else{
                warningAlert(res.data.msg)
            }
        })
    },
    // 点击编辑
    bianji(id){
        this.$emit('bianji',id)
    }
  },
  computed: {
    ...mapGetters({
      list: "role/list",
    }),
  },
  mounted() {
    this.reqchangelist();
  },
};
</script>

<style lang="less" scoped>
</style>